package com.xysoft.admin.web;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xysoft.admin.service.IProblemService;

@Controller
@RequestMapping(value = "/admin/problem.jspx")
public class ProblemController extends BaseController {
	private IProblemService problemService;
	
	@RequestMapping(params = "index")
	public String get(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		String res = this.problemService.get(request, session);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indexOFtype")
	public String getType(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		String res = this.problemService.getType();
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indexOFalltype")
	public String getAllType(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		String res = this.problemService.getAllType();
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indexOFnumber")
	public String getNumber(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		String res = this.problemService.getNumber(request, session);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "add")
	@ResponseBody
	public Map<String, Object> add(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		return this.problemService.addOrModify(request, session);
	}
	
	@RequestMapping(params = "edit")
	@ResponseBody
	public Map<String, Object> edit(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		return this.problemService.addOrModify(request, session);
	}
	
	@RequestMapping(params = "data")
	public String data(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws Exception {
		response.setContentType("text/html; charset=UTF-8");
		boolean success = this.problemService.data(request, session);
		if (success) {
			response.getWriter().print("{ success:true, title: '上传成功！', msg : '' }");	
		} else {
			response.getWriter().print("{ success:true, title: '上传失败！', msg : '' }");	
		}
		return null;
	}
	
	@RequestMapping(params = "dataOFfile")
	public String getData(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		String res = this.problemService.getData(request, session);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "dataOFremove")
	@ResponseBody
	public Map<String, Object> removeData(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		return this.problemService.removeData(request, session);
	}
	
	@RequestMapping(params = "dataOFdetail")
	@ResponseBody
	public Map<String, Object> getDetail(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		return this.problemService.getDetail(request, session);
	}
	
	@RequestMapping(params = "dataOFsave")
	@ResponseBody
	public Map<String, Object> saveDetail(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws IOException {
		return this.problemService.saveDetail(request, session);
	}
	
	@RequestMapping(params = "dataOFrar")
	public String importData(HttpServletResponse response, HttpServletRequest request, 
			HttpSession session) throws Exception {
		response.setContentType("text/html; charset=UTF-8");
		boolean success = this.problemService.importData(request, session);
		if (success) {
			response.getWriter().print("{ success:true, title: '导入成功！', msg : '' }");	
		} else {
			response.getWriter().print("{ success:true, title: '导入失败！', msg : '' }");	
		}
		return null;
	}

	@Autowired
	public void setProblemService(IProblemService problemService) {
		this.problemService = problemService;
	}
}
